package com.qfedu.yanglao20app.handicapped.attention.service.impl;

import com.qfedu.yanglao20.entity.handicapped.HandicappedAttention;
import com.qfedu.yanglao20app.handicapped.attention.dao.AppHandicappedAttentionDao;
import com.qfedu.yanglao20app.handicapped.attention.service.AppHandicappedAttentionService;
import com.qfedu.yanglao20app.handicapped.attention.vo.AttentionVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yujie
 * @data 2023/5/19 22:49
 */
@Service
public class AppHandicappedAttentionServiceImpl implements AppHandicappedAttentionService {

    @Resource
    private AppHandicappedAttentionDao appHandicappedAttentionDao;

    @Override
    public List<AttentionVO> attentionList(Integer handicappedId) {

        List<AttentionVO> attentionVOS = appHandicappedAttentionDao.attentionList(handicappedId);

        for (AttentionVO a :
                attentionVOS) {

            if (a.getHandicappedId() == null) {
                a.setHandicappedId("关注");
            } else {
                a.setHandicappedId("取消关注");
            }

        }
        return attentionVOS;
    }

    @Override
    public void insertAttention(HandicappedAttention attention) {

        Integer count =
                appHandicappedAttentionDao.selectByByHidAndId(attention.getId(), attention.getHandicappedId());

        if (count != 0) {
            appHandicappedAttentionDao.deleteByHidAndId(attention.getId(), attention.getHandicappedId());
        } else {
            appHandicappedAttentionDao.insertAttention(attention);
        }

    }
}
